package com.itheima.user.controller;

import com.itheima.user.pojo.User;
import com.itheima.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

/**
 * @作者 itcast
 * @创建日期 2020/11/8 9:50
 **/
@RestController
@RequestMapping("user")
public class UserController {
    @Value("${server.port}")
    int port;
    @Autowired
    UserService userService;
    @GetMapping("{id}")
    public String findById(@PathVariable("id")Long id){
        System.out.println( "方法被调用  调用端口==>"+port );
        if(id == 1){
            throw new RuntimeException();
        }
        User byId = userService.findById(id);
        return "用户信息==>"+byId.getUserName() + "  调用端口==>"+port ;
    }
    @PostMapping
    public String add(@RequestBody User user){
        System.out.println("添加用户: " + user);
        return "添加成功" ;
    }
}
